﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.Caching;
using System.Text;

namespace Htss.Platform.Web.Cache
{
    public class Main
    {
        /// <summary>
        /// 删除缓存
        /// </summary>
        /// <param name="Context"></param>
        /// <param name="key"></param>
        public void Delete(HttpContextBase Context, string key)
        {
            if (Context.Cache[key] != null)
            {
                Context.Cache.Remove(key);
            }
        }
        /// <summary>
        /// 获取缓存
        /// </summary>
        /// <param name="Context"></param>
        /// <param name="key"></param>
        public object Get(HttpContextBase Context, string key)
        {
            if (Context.Cache[key] != null)
            {
                return Context.Cache.Get(key);
            }
            else
            {
                return null;
            }
        }
        /// <summary>
        /// 创建缓存
        /// </summary>
        /// <param name="Context"></param>
        /// <param name="key"></param>
        /// <param name="value"></param>
        /// <param name="time"></param>
        /// <param name="timeSpan"></param>
        public void Add(HttpContextBase Context, string key, Object value, int time, int timeSpan)
        {
            if (Context.Cache[key] == null)
            {
                //创建缓存
                Context.Cache.Insert(key, value, null, DateTime.MaxValue, TimeSpan.FromMinutes(timeSpan));
            }
        }
        /// <summary>
        /// 根据传来的值判断该值是否在缓存中出现
        /// </summary>
        /// <param name="Context"></param>
        /// <param name="key"></param>
        /// <returns></returns>
        public bool IsCache(HttpContextBase Context, string key)
        {
            return Context.Cache[key] == null ? false : true;
        }
    }
}
